package com.zy.controller;

import com.zy.entity.Page;
import com.zy.entity.Video;
import com.zy.entity.VideoText;
import com.zy.service.ManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.websocket.server.PathParam;
import java.util.List;
import java.util.Map;

@Controller
public class ManagementController
{

    @Autowired
    private ManagementService managementService;

    /**
     * 后台视频管理搜索视频
     * @param pageNo
     * @param pageSize
     * @param typeName
     * @param userName
     * @return
     */
    @ResponseBody
    @GetMapping("/searchVideo")
    public Page<VideoText> searchVideo(@PathParam("pageNo") int pageNo, @PathParam("pageSize") int pageSize,
                                       String typeName, String userName)
    {
        return managementService.searchVideoListByPageNoAndPageSizeAndTypeNameOrUserName(pageNo, pageSize, typeName, userName);
    }

    /**
     * 通过id查询删除信息并返回信息
     * @param pageNo
     * @param pageSize
     * @param typeName
     * @param userName
     * @param id
     * @return
     */
    @ResponseBody
    @GetMapping("/deleteVideo")
    public Page<VideoText> deleteVideoById(@PathParam("pageNo") int pageNo, @PathParam("pageSize") int pageSize,
                                           String typeName, String userName,int id)
    {
        managementService.deleteVideoById(id);
        return managementService.searchVideoListByPageNoAndPageSizeAndTypeNameOrUserName(pageNo, pageSize, typeName, userName);
    }

    /**
     * 统计视频每年视频数量
     * @param video
     * @return
     */
    @ResponseBody
    @GetMapping("/selectVideoCount")
    public Map<String,Object> selectVideoCount(Video video)
    {
        return managementService.selectVideoCount(video);
    }

    /**
     * 统计视频每年视频数量
     * @param video
     * @return
     */
    @ResponseBody
    @GetMapping("/selectVideoCount2")
    public List<Map<String,Object>> selectVideoCount2(Video video)
    {
        return managementService.selectVideoCount2(video);
    }

    /**
     * 统计个人视频每年视频数量
     * @param video
     * @return
     */
    @ResponseBody
    @GetMapping("/selectPersionalVideoCount")
    public List<Map<String,Object>> selectPersionalVideoCount(Video video)
    {
        return managementService.selectPersionalVideoCount(video);
    }

}
